<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用代理实现单例模式</title>
</head>
<body>
<script>
    var CreateDiv = function (html) {
        this.html = html;
        this.init();
    };

    CreateDiv.prototype.init = function () {
        var div = document.createElement('div');
        div.innerHTML = this.html;
        document.body.appendChild(div);
    };

    var ProxySingletonCreateDiv = (function () {
        var instance;
        return function (html) {
            if(!instance){
                instance = new CreateDiv(html);
            }
            return instance;
        }
    })();

    var a = new ProxySingletonCreateDiv('sven1');
    var b = new ProxySingletonCreateDiv('sven2');

    console.log(a);
    console.log(b);
    console.log(a===b);
</script>
</body>
</html>